/**
 * @file tiny_ring_queue.h
 * @author 张恒宣 
 * @LastEditTime 2024/9/22
 * 
 * MIT License
 *
 * Copyright (c) 2025 张恒宣 luckkeymail@163.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef __TINY_RING_QUEUE_H__
#define __TINY_RING_QUEUE_H__

/*********************
 *       头文件
 *********************/

#include "tiny_def.h"

/**********************
 *      类型定义
 **********************/

typedef void (*tiny_rq_copy_callback)(tiny_uint8_t *, tiny_uint8_t *, tiny_uint32_t);

typedef enum
{
	QUEUE_OK = 0,
	QUEUE_FULL,
	QUEUE_EMPTY,
	QUEUE_ERROR,
} QUEUE_RET_STATUS;


typedef struct
{
	tiny_uint32_t block_size;
	tiny_uint32_t block_num;
	tiny_int32_t head;
	tiny_int32_t tail;
	tiny_rq_copy_callback queue_data_copy;
	tiny_uint8_t *buf;
} tiny_ring_queue_t;

/**********************
 *      函数声明
 **********************/

void tiny_queue_buf_data_copy(tiny_uint8_t *dst, tiny_uint8_t *src, tiny_uint32_t size);
void tiny_queue_int64_data_copy(tiny_uint8_t *dst, tiny_uint8_t *src, tiny_uint32_t size);

tiny_ring_queue_t *tiny_ring_queue_create(tiny_uint32_t block_num, tiny_uint32_t block_size, tiny_rq_copy_callback queue_data_copy);
void tiny_ring_queue_free(tiny_ring_queue_t *rq);
QUEUE_RET_STATUS tiny_ring_queue_push(tiny_ring_queue_t *rq, tiny_uint8_t *buf, tiny_uint32_t size);
QUEUE_RET_STATUS tiny_ring_queue_pop(tiny_ring_queue_t *rq, tiny_uint8_t *buf, tiny_uint32_t size);
tiny_int32_t tiny_ring_queue_isempty(tiny_ring_queue_t *rq);

#endif //!__TINY_RING_QUEUE_H__
